<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>发布公告</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/v1/css/base/coach.css">

</head>
<body>

<div class="layui-container">
    <input type="hidden" th:value="${notice.id}" name="notId">
    <input type="hidden" th:value="${notice.content}" name="notContent">

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;text-align: center">
        <legend>公告栏</legend>
    </fieldset>
    <div class="layui-row">
        <textarea id="demo" style="display: none;"></textarea>
    </div>
    <div class="layui-row" style="text-align: center;margin-top: 10px">
        <button class="layui-btn layui-btn-normal btn-submit">提交</button>
    </div>

</div>
<div class="truck-wrapper" id="show-loading">
    <div class="truck">
        <div class="truck-container">
            <img src="http://i.lymtr.cn/cmhi/logo/3.2.png" width="100%">
        </div>
        <div class="glases"></div>
        <div class="bonet"></div>
        <div class="base"></div>
        <div class="base-aux"></div>
        <div class="wheel-back"></div>
        <div class="wheel-front"></div>
        <div class="smoke"></div>
    </div>
</div>
<script src="/static/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'layedit'], function () {
        var layer = layui.layer
            , form = layui.form;
        var layedit = layui.layedit;
        var $ = layui.$;
        $("#show-loading").hide();

        var index = layedit.build('demo', {
            uploadImage: {
                url: '' //接口url
                , type: '' //默认post
            },
            height: 505
        });
        var notContent = $('[name=notContent]').val();
        layedit.setContent(index, notContent, true);


        $(".btn-submit").on("click", function () {
            var content = layedit.getContent(index);
            var data = {
                content: content,
                id:$("[name=notId]").val()
            };
            console.log(content);
            if (content == '' || content == undefined) {
                layer.msg("填写内容不能为空！");
                return;
            }
            var loadIndex = layer.load(1); //换了种风格
            $.ajax({
                url: "/rest/notice/edit",
                type: "post",
                data: data,
                dataType: "json",
                success: function (data) {
                    if (data.code == 'success') {
                        layer.msg("修改成功");
                    } else {
                        var msg = data.msg != '' ? data.msg : "新增失败";
                        layer.msg(msg);
                    }
                }
            });
            layer.close(loadIndex);
        })

    });
</script>
</body>
</html>
